// 菜单模块的接口
import request from '../../../utils/request'
// 引入ts类型
import type { PermisstionResponseData, MenuParams } from './type'
// 枚举地址
enum API {
  // 获取全部菜单与按钮的标识数据
  ALLMENU_URL = '/admin/acl/permission',
  // 给某一级菜单添加一个子菜单
  ADDMENU_URL = '/admin/acl/permission/save',
  // 更新已有菜单
  UPDATEMENU_URL = '/admin/acl/permission/update',
  // 删除菜单
  DELETEMENU_URL = '/admin/acl/permission/remove/',
}
// 获取全部菜单与按钮的标识数据
export const reqAllPermisstion = () =>
  request.get<any, PermisstionResponseData>(API.ALLMENU_URL)
// 添加或者更新菜单
export const reqAddOrUpdatePermisstion = (data: MenuParams) => {
  if (data.id) {
    return request.put<any, any>(API.UPDATEMENU_URL, data)
  } else {
    return request.post<any, any>(API.ADDMENU_URL, data)
  }
}
// 删除菜单
export const reqRemoveMenu = (id: number) =>
  request.delete<any, any>(API.DELETEMENU_URL + id)
